package com.bss.model;

// Generated Oct 27, 2011 10:37:49 PM by Hibernate Tools 3.3.0.GA

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.bss.AbstractEntity;

/**
 * Room generated by hbm2java
 */
@Entity
@Table(name = "room")
public class Room extends AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6987330768818685244L;

	private int id;

	@NotNull
	@Size(min = 1, max = 5)
	private String roomNumber;

	@NotNull
	private Building building = new Building();

	@Min(1)
	@Max(10)
	private Integer floor;

	@Min(1)
	@Max(300)
	private Integer numberOfBeds;

	private boolean dormitory;
	private boolean ac;

	// @NotNull
	// @Min(1)
	private Integer rate = 0;

	private int proposedRate;

	private Set<RoomBooking> roomBookings = new HashSet<RoomBooking>(0);

	private Set<Bed> beds = new HashSet<Bed>(0);

	@Transient
	private boolean occupied;

	public Room() {
	}

	public Room(String roomNumber, Building building, Integer floor,
			Integer numberOfBeds, boolean dormitory, boolean ac, Integer rate) {
		super();
		this.roomNumber = roomNumber;
		this.building = building;
		this.floor = floor;
		this.numberOfBeds = numberOfBeds;
		this.dormitory = dormitory;
		this.ac = ac;
		this.rate = rate;
	}

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return this.id;
	}

	public void setId(final Integer id) {
		this.id = id;
	}

	public void setRoomNumber(final String roomNumber) {
		this.roomNumber = roomNumber;
	}

	@Column(name = "roomNumber", unique = true, nullable = false)
	public String getRoomNumber() {
		return this.roomNumber;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
	@JoinColumn(name = "idBuilding")
	public Building getBuilding() {
		return this.building;
	}

	public void setBuilding(final Building building) {
		this.building = building;
	}

	@Column(name = "floor")
	public Integer getFloor() {
		return this.floor;
	}

	public void setFloor(final Integer floor) {
		this.floor = floor;
	}

	@Column(name = "numberOfBeds")
	public Integer getNumberOfBeds() {
		return this.numberOfBeds;
	}

	public void setNumberOfBeds(final Integer numberOfBeds) {
		this.numberOfBeds = numberOfBeds;
	}

	@Column(name = "dormitory")
	public boolean isDormitory() {
		return this.dormitory;
	}

	public void setDormitory(final boolean dormitory) {
		this.dormitory = dormitory;
	}

	@Column(name = "ac")
	public boolean getAc() {
		return this.ac;
	}

	public void setAc(final boolean ac) {
		this.ac = ac;
	}

	@Column(name = "rate")
	public Integer getRate() {
		return this.rate;
	}

	public void setRate(final Integer rate) {
		this.rate = rate;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "room")
	public Set<RoomBooking> getRoomBookings() {
		return this.roomBookings;
	}

	public void setRoomBookings(final Set<RoomBooking> roombookings) {
		this.roomBookings = roombookings;
	}

	@OrderBy("bedNumber ASC")
	@OneToMany(fetch = FetchType.EAGER, mappedBy = "room")
	public Set<Bed> getBeds() {
		return this.beds;
	}

	public void setBeds(final Set<Bed> beds) {
		this.beds = beds;
	}

	public void setOccupied(final boolean occupied) {
		this.occupied = occupied;
	}

	@Transient
	public boolean isOccupied() {
		return this.occupied;
	}

	public void setProposedRate(final int proposedRate) {
		this.proposedRate = proposedRate;
	}

	@Transient
	public int getProposedRate() {
		return this.proposedRate;
	}

	@Override
	public String toString() {
		return getRoomNumber();
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date", length = 19)
	public Date getDate() {
		return this.date;
	}

	@Transient
	public RoomBooking getCurrentBooking() {
		for (RoomBooking roomBooking : getRoomBookings()) {
			return roomBooking;
		}
		return null;
	}

}
